This invention relates generally to object-oriented programming, and more particularly to hierarchical object models.
Object-oriented programming (OOP) languages are rapidly replacing procedure-oriented programming languages which were prevalent in the early 1970""s. An object is an encapsulated module of code and related data which is externally accessible through well-defined and controlled connection points, known as the object""s methods and properties. The values of an object""s data defines the object""s xe2x80x9cstate.xe2x80x9d Another object can determine the first object""s state and optionally modify that state by specifying the first object""s methods and properties in a message directed to the first object. A collection of objects is created to perform the functions a programmer wants to include in a computer application. The OOP paradigm commonly supports the collection as a hierarchy of interconnected objects in a parent-child tree model. The programmer constructs the hierarchy so that each object in the hierarchy is logically connected to other objects from which it needs to receive messages As long as the program is based on a set of actions performed in a predefined sequence, the hierarchical object model and messaging in a standard OOP system works well.
However, in interactive operating systems, such as Microsoft Windows, a user controls the sequence of program execution by choosing actions to be performed in a relatively random fashion. Each choice creates an event that the application must process. The original property/method paradigm only permitted an object to process incoming messages, but interactive operating systems require that the object also output xe2x80x9ceventsxe2x80x9d in response to the user""s actions. Various extensions to the basic OOP paradigm have been implemented to handle events, but all require additional interconnections among the objects in the hierarchy to receive events from other objects. Such additional interconnections increase the complexity of the model.
Whenever a child object is created or removed from the hierarchy, its parent object xe2x80x9cfiresxe2x80x9d or xe2x80x9csourcesxe2x80x9d an event that notifies other objects of the creation or removal of the child object. In a hierarchical object model in which entire branches of objects can be transient, connecting and receiving events from other objects becomes extremely cumbersome and problematic due to the large amount of overhead associated with tracking the transient objects. When the hierarchy structure extends to great depths and most of the objects in the hierarchy are transient, an object or program that needs to detect the creation and removal of an object far down in the hierarchy must xe2x80x9clistenxe2x80x9d for events from all the objects above the target object in which it is interested to determine when a new branch containing the target object is created or destroyed. Thus, the listening object must track the creation and removal of all objects above the target object.
One approach used to ease the overhead burden of following all events from all parent objects of the target object is xe2x80x9cevent bubblingxe2x80x9d in which each object xe2x80x9cre-firesxe2x80x9d or xe2x80x9cbubbles upxe2x80x9d to its parent object each event it receives from its children objects. The listening object now listens on the target""s highest parent object. However, event bubbling merely redistributes the overhead burden among the objects in the hierarchy without reducing the overall costs of tracking each transient object. No attempt is made by the parent object to determine what events may be of interest to the listening object so the parent object broadcasts all events in an unorganized fashion. Furthermore, adding new events to an object in a hierarchy under the event bubbling scheme perturbs the established event structure and introduces compatibility issues.
An additional problem arises when listening for transient objects in a hierarchical model. When the lower object terminates, all the connections between itself and the other objects in the hierarchy must be completely removed, introducing additional overhead costs into the system. If the connection between the lower object and a higher object is not xe2x80x9ctorn-down,xe2x80x9d the higher object cannot terminate when necessary, leaving xe2x80x9cghostxe2x80x9d objects in the hierarchy. This problem is particularly acute when using the event bubbling scheme described above because of all the connection required to support the re-firing of events up the hierarchy.
Therefore, a method is needed that permits interested objects to listen for events occurring in a hierarchical object model that pertain to certain objects. The interested objects should receive notification of such events in an organized fashion. The method should also decrease the overhead associated with current event-driven object-oriented programs.
The above-mentioned shortcomings, disadvantages and problems are addressed by the present invention, which will be understood by reading and studying the following specification
A computerized method is described that centralizes the receiving and sourcing of events occurring in a hierarchical object model. The method creates a monitoring object, logically coupled to an object in the hierarchy, to which the events in the hierarchy are routed. The monitoring object has a plurality of properties, or accessor functions, each of which corresponds to the events that pertain to a class of objects in the hierarchy and has a parameter for designating an object in the class. A listener objects or a process on behalf of the listener object, causes the initiation of a notification request. The notification request is initiated by calling the property corresponding to the class of the target object, the property having been parameterized with an identifier for the target object. When the method receives the notification request, it determines if a filter object characterized by the parameterized property in the request has been created and creates the filter object if it does not exist. The appropriate filter object is logically coupled between the monitoring object and the listener object. Events pertaining to the target object as designated by the parameterized property are transmitted from the monitoring object to the filter object for sourcing to the listener object.
If a second notification request is received that specifies the same property with the same parameterization as in the first request, the method logically couples the same filter object to a listener object that caused the initiation of the second notification request or on whose behalf the notification request was initiated. Otherwise, the method creates a filter object characterized by the parameterized property in the second notification request and couples it to the listener object that caused the initiation of the second notification request or on whose behalf the notification request was initiated.
An event received by the event monitoring object for which there is no corresponding filter objects is discarded. Optionally, a filter object is not destroyed when all the listener objects to which the filter object is coupled terminate. The identifier can designate a unique object, objects in a class that occupy a certain level of the hierarchy, or all objects in a class regardless of their level. xe2x80x9cAlternatively, the event monitoring object creates a event filter object without receiving a notification request.xe2x80x9d
In another aspect of the invention, a hierarchical object model for an object-oriented program is described which contains a plurality of program objects logically coupled together in a hierarchical relationship. The model also contains an event monitoring object and plurality of event filter objects. The plurality of program objects fire events during execution of the program. The event monitoring object is logically coupled to an object in the hierarchical object model and serves as a routing destination for the events. The plurality of event filter objects are logically coupled to the event monitoring object. Each event filter object is created by the event monitoring object to source events pertning to an instance of a program object as determined by a corresponding parameterized property. A listener object is logically coupled to the appropriate event filter object based on the parameterized property in a notification request received by the event monitoring object.
An event sourcing and filtering program executed from a computer-readable medium by a processing unit in a computer system to create the above described hierarchical object model is also disclosed.
The present invention reduces the overhead burden in a hierarchical object model by creating an event monitoring object to which all events are directed, alleviating the redundancy of re-firing events up the hierarchy and eliminating the need to xe2x80x9ctear downxe2x80x9d complicated connections between objects. Because the event monitoring object and the filter objects source to the listener objects only those object-related events in which the listener objects are interested, the listener objects do not have to sift through unorganized broadcasts of events from all objects to find the ones they need. Furthermore, the event monitoring object can be tailored to receive only a subset of all fired events depending on the nature of the hierarchical object model. The present invention simplifies the programming of applications using a hierarchical object model and increases the performance of such applications.
The present invention describes systems, clients, servers, methods, and computer-readable media of varying scope. In addition to the aspects and advantages of the present invention described in this summary, further aspects and advantages of the invention will become apparent by reference to the drawings and by reading the detailed description that follows.